<?php
	session_start(); 
	ob_start();
	
	require("./inc/config-system.inc.php");
	require("./inc/config-db.inc.php");
	require("./inc/fm.inc.php");
	require("./class/adodb/adodb.inc.php");

	$q = strtolower($_GET["q"]);
	if (!$q) { return; }

	$ty = strtolower($_GET["ty"]);

	// connection database
	$objConn = ADONewConnection(DB_DRIVER); 
	$objConn->Connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
	//$objConn->debug = TRUE;
	
	if ($ty == 'ar') {
		$sqlCommand = "SELECT * FROM tbl_gl WHERE ( gl_account LIKE '1%' OR gl_account LIKE '2%' OR gl_account LIKE '3%' OR gl_account LIKE '4%' ) ORDER BY gl_account";
	} elseif ($ty == 'ap') {
		$sqlCommand = "SELECT * FROM tbl_gl WHERE ( gl_account LIKE '1%' OR gl_account LIKE '2%' OR gl_account LIKE '3%' OR gl_account LIKE '5%' ) ORDER BY gl_account";
	} elseif ($ty == 'adj') {
		$sqlCommand = "SELECT * FROM tbl_gl ORDER BY gl_account";
	}
	
	$recordset = $objConn->Execute($sqlCommand);
	
	$items[] = array();
	while (!$recordset->EOF) {
		// create associative array
		$items[$recordset->fields["gl_description"]] = $recordset->fields["gl_account"];

		$recordset->MoveNext();
	}

	//print_r($items); exit();
	
	foreach ($items as $key=>$value) {
		if (strpos(strtolower($key), $q) !== false) {
			echo "$key|$value\n";
		}
	}
?>